import java.util.*;

public class Leet49 {
    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String,List<String>> map = new HashMap<>();
        for (String str : strs) {
            int[] te = new int[26];
            for (char c : str.toCharArray())
                te[c-'a']++;
            String key = Arrays.toString(te);
            List<String> list = map.getOrDefault(key, new ArrayList<>());
            list.add(str);
            map.put(key, list);
        }
        return new ArrayList<>(map.values());
    }
}
